using System;
using System.IO;

public interface ILogObserver
{
    int id { get; set; }
    void Insert(string message);
}

public class LogSubject
{
    private List<ILogObserver> observers;

    public LogSubject()
    {
        observers = new List<ILogObserver>();    
    }

    public void Register(ILogObserver obs)
    {
        if (!observers.Exists(ob=>ob.id==obs.id)
        {
            observers.add(obs); 
        }
    }

    public void Remove(ILogObserver obs)
    {
        if (observers.Exists(ob=>ob.id==obs.id)
        {
            observers.Remove(obs); 
        }
    }

    public void Notify(string message)
    {
        foreach (ILogObserver obs in observers)
        {
            obs.Insert(message);
        }
    }
}

/// <summary>控制台日志</summary>
public class ConsoleLog: ILogObserver
{

    public int id { get; set; }    

    public void Insert(string message)
    {
        System.Console.WriteLine(message);
    }
}

/// <summary>文本日志</summary>
public class TextLog: ILogObserver
{
    public int id { get; set; }    

    public void Insert(string message)
    {
        string filePath = "x:\\log.txt";
        System.File.AppendLine(filePath, message);
    }
}

